/*
	Program Counter Register
*/
module pcReg
(
	input	wire			clk,
	input	wire			rst,
	
	input	wire			jumpFlag,
	input	wire			branchFlag,
	input	wire	[31:0]	jumpAddr,				// jumpAddr calculate by specialAddr
    input   wire    [31:0]  branchOffset,
	
	input	wire			storeOp,
	input	wire			loadOp,
	input	wire			lsuDone,				// if lsuDone == 0,means lsu is read or write data,so need hold the instruction.
													// The lsuDone is depend on your bus and peripheral.
	
	output	reg		[31:0]	pc						// pc[31:02] link to InstROM's [29:00],because the InstROM's width also is 32.
);

	always @(negedge clk or posedge rst) begin
		if 		( rst )					pc <= 32'b0;
		else if ( jumpFlag )            pc <= jumpAddr;
        else if ( branchFlag ) 			pc <= pc + branchOffset;
		else 							pc <= ((storeOp | loadOp) & (!lsuDone) ) ? pc : pc + 32'h4;
	end
endmodule

